package com.happe.foodeasy.manage.service.impl;

import com.happe.foodeasy.manage.dao.ImagePhotoMapper;
import com.happe.foodeasy.manage.dto.ImagePhotoDTO;
import com.happe.foodeasy.manage.image.entity.ImagePhotoEntity;
import com.happe.foodeasy.manage.service.ImagePhotoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ImagePhotoServiceImpl implements ImagePhotoService {
    @Autowired
    private ImagePhotoMapper imagePhotoMapper;

    @Override
    public void save(ImagePhotoDTO photoDTO) {
        imagePhotoMapper.save(photoDTO);
    }

    @Override
    public ImagePhotoEntity findFirstTargetCommodityImage(long commodityId) {
        ImagePhotoDTO dto = new ImagePhotoDTO();
        dto.setCommodityBaseEntityId(commodityId);
        dto.setPhotoOrder(1);
        List<ImagePhotoEntity> allImages = imagePhotoMapper.findImages(dto);
        return allImages.size() > 0 ? allImages.get(0) : null;
    }


}
